﻿var b = true;

function ChangeImage() {
    var ranNum = Math.floor(Math.random() * 99999999);
    AjaxRequest.get(
    {
        'onLoading': function(req) {
            $("#divLoading").show();
        },
        'onSuccess': function(req) {
            gmobj('imgValidCode').src = "/Services/CapchaImage.ashx?Code=" + ranNum;
            $("#divLoading").hide();
        }
        , 'onError': function(req) { }
    });
}


function ChangeStatus(field, vType, vMsg) {
    if (vType == 1) {
        if (field.value == vMsg) { field.value = ''; }
    } else if (vType == 0) {
        if (field.value == '') { field.value = vMsg; }
    }
}

function getNodeValue(o) {
    try {
        return o.item(0).firstChild.nodeValue;
    }
    catch (err) {
        return '';
    }
}

var MenuV2 = {
    selectedById: function(cId, sId) {
        for (i = 0; i < MenuItem.length - 1; i++) {
            if (MenuItem[i] == cId) {
                gmobj("mnu_item_" + cId).className = "selected";
            } else {
                gmobj("mnu_item_" + sId).className = "selected";
            }
        }
        gmobj("mnu_item_0").className = "";
    }
}

var Vote = {
    writeVote: function(vId, divId) {
        try {
            AjaxRequest.get(
	        {
	            "url": "/Resource/Articles/Votes/" + vId + ".xml"
		        , 'onSuccess': function(req) {
		            var strClass = "";
		            var strOut = "";
		            var Total = 0;
		            var TotalVote = 0;
		            var TotalRate = 0;

		            TotalVote = getNodeValue(req.responseXML.getElementsByTagName('XML').item(0).getElementsByTagName('TotalRate'));
		            Total = getNodeValue(req.responseXML.getElementsByTagName('XML').item(0).getElementsByTagName('TotalVote'));

		            if (TotalVote == 0) {
		                TotalRate = 0;
		            } else {
		                TotalRate = Math.ceil(parseInt(Total) / parseInt(TotalVote));
		            }

		            switch (parseInt(TotalRate)) {
		                case 0:
		                    strClass = "nostar";
		                    break;
		                case 1:
		                    strClass = "onestar";
		                    break;
		                case 2:
		                    strClass = "twostar";
		                    break;
		                case 3:
		                    strClass = "threestar";
		                    break;
		                case 4:
		                    strClass = "fourstar";
		                    break;
		                case 5:
		                    strClass = "fivestar";
		                    break;
		                default:
		                    strClass = "nostar";
		                    break;
		            }

		            if (strClass.length < 1) {
		                strClass = "nostar";
		            }

		            strOut = "";
		            if (getCookie("ArticleVote_" + vId) == null) {
		                strOut = strOut.concat('<ul class="rating ').concat(strClass).concat('">');
		                strOut = strOut.concat("<li class=\"one\"><a href=\"javascript:void(0);\" onfocus=\"this.blur();\" onclick=\"javascript:Vote.upVote(" + vId + ",1," + TotalVote + "," + Total + ",'" + divId + "');\" title=\"1 Star\">1</a></li>");
		                strOut = strOut.concat("<li class=\"two\"><a href=\"javascript:void(0);\" onfocus=\"this.blur();\" onclick=\"javascript:Vote.upVote(" + vId + ",2," + TotalVote + "," + Total + ",'" + divId + "');\" title=\"2 Stars\">2</a></li>");
		                strOut = strOut.concat("<li class=\"three\"><a href=\"javascript:void(0);\" onfocus=\"this.blur();\" onclick=\"javascript:Vote.upVote(" + vId + ",3," + TotalVote + "," + Total + ",'" + divId + "');\" title=\"3 Stars\">3</a></li>");
		                strOut = strOut.concat("<li class=\"four\"><a href=\"javascript:void(0);\" onfocus=\"this.blur();\" onclick=\"javascript:Vote.upVote(" + vId + ",4," + TotalVote + "," + Total + ",'" + divId + "');\" title=\"4 Stars\">4</a></li>");
		                strOut = strOut.concat("<li class=\"five\"><a href=\"javascript:void(0);\" onfocus=\"this.blur();\" onclick=\"javascript:Vote.upVote(" + vId + ",5," + TotalVote + "," + Total + ",'" + divId + "');\" title=\"5 Stars\">5</a></li>");
		                strOut = strOut.concat('</ul>');
		            } else {
		                strOut = strOut.concat('<ul class="rating ').concat(strClass).concat('">');
		                strOut = strOut.concat("<li class=\"one\">&nbsp;</li>");
		                strOut = strOut.concat("<li class=\"two\">&nbsp;</li>");
		                strOut = strOut.concat("<li class=\"three\">&nbsp;</li>");
		                strOut = strOut.concat("<li class=\"four\">&nbsp;</li>");
		                strOut = strOut.concat("<li class=\"five\">&nbsp;</li>");
		                strOut = strOut.concat('</ul>');
		            }
		            gmobj(divId).innerHTML = strOut;
		        }
		        , 'onError': function(req) {
		            strClass = "nostar";
		            strOut = "";
		            strOut = strOut.concat('<ul class="rating ').concat(strClass).concat('">');
		            strOut = strOut.concat("<li class=\"one\"><a href=\"javascript:void(0);\" onfocus=\"this.blur();\" onclick=\"javascript:Vote.upVote(" + vId + ",1,0,0,'" + divId + "');\" title=\"1 Star\">1</a></li>");
		            strOut = strOut.concat("<li class=\"two\"><a href=\"javascript:void(0);\" onfocus=\"this.blur();\" onclick=\"javascript:Vote.upVote(" + vId + ",2,0,0,'" + divId + "');\" title=\"2 Stars\">2</a></li>");
		            strOut = strOut.concat("<li class=\"three\"><a href=\"javascript:void(0);\" onfocus=\"this.blur();\" onclick=\"javascript:Vote.upVote(" + vId + ",3,0,0,'" + divId + "');\" title=\"3 Stars\">3</a></li>");
		            strOut = strOut.concat("<li class=\"four\"><a href=\"javascript:void(0);\" onfocus=\"this.blur();\" onclick=\"javascript:Vote.upVote(" + vId + ",4,0,0,'" + divId + "');\" title=\"4 Stars\">4</a></li>");
		            strOut = strOut.concat("<li class=\"five\"><a href=\"javascript:void(0);\" onfocus=\"this.blur();\" onclick=\"javascript:Vote.upVote(" + vId + ",5,0,0,'" + divId + "');\" title=\"5 Stars\">5</a></li>");
		            strOut = strOut.concat('</ul>');

		            gmobj(divId).innerHTML = strOut;
		        }
	        });
        } catch (err) { return ""; }
    },
    upVote: function(vId, banchodiem, tongsoluot, sodiembinhchoncu, divId) {
        try {
            var sodiembinhchonmoi;
            sodiembinhchonmoi = banchodiem + sodiembinhchoncu;
            tongsoluot = parseInt(tongsoluot) + 1;

            AjaxRequest.get(
                {
                    "url": "/Services/Votes.ashx?sId=" + vId + "&sodiembinhchonmoi=" + sodiembinhchonmoi + "&tongsoluot=" + tongsoluot
                    , 'onSuccess': function(req) {
                        if (req.responseText == "OK") {
                            alert("Cam on ban da danh gia.");
                            Vote.writeVote(vId, divId);
                        } else if (req.responseText == "Voted") {
                            alert("Ban da binh chon cho bai nay roi.");
                        }
                    }
                    , 'onError': function(req) {
                        alert(req);
                    }
                });
        } catch (err) { return ""; }
    }
}

var Util = {
    sociable: function(vLink, vTitle, vAbstract, vId) {
        var strOut = "";
        vTitle = vTitle.replace("'", "");
        vAbstract = vAbstract.replace("'", "");
        strOut = strOut.concat("<div class=\"sociable\">");
        strOut = strOut.concat("<div class=\"sociable_tagline\">");
        strOut = strOut.concat("<strong>Share and Enjoy:</strong>");
        strOut = strOut.concat("</div>");
        strOut = strOut.concat("<ul>");
        strOut = strOut.concat("<li class=\"sociablefirst\"><a title=\"Digg\" href=\"javascript:window.location='http://digg.com/submit?phase=2&amp;url=" + Url.encode(vLink) + "&amp;title=" + Url.encode(vTitle) + "';\" target=\"_blank\" id=\"digg\" rel=\"nofollow\"><img class=\"sociable-hovers\" alt=\"Digg\" title=\"Digg\" src=\"/template/Justin/images/digg.png\"/></a></li>");
        strOut = strOut.concat("<li><a title=\"del.icio.us\" href=\"javascript:window.location='http://delicious.com/post?url=" + Url.encode(vLink) + "&amp;title=" + Url.encode(vTitle) + "';\" target=\"_blank\" id=\"del.icio.us\" rel=\"nofollow\"><img class=\"sociable-hovers\" alt=\"del.icio.us\" title=\"del.icio.us\" src=\"/template/Justin/images/delicious.png\"/></a></li>");
        strOut = strOut.concat("<li><a title=\"Facebook\" href=\"javascript:window.location='http://www.facebook.com/share.php?u=" + Url.encode(vLink) + "&amp;t=" + Url.encode(vTitle) + "';\" target=\"_blank\" id=\"facebook\" rel=\"nofollow\"><img class=\"sociable-hovers\" alt=\"Facebook\" title=\"Facebook\" src=\"/template/Justin/images/facebook.png\"/></a></li>");
        strOut = strOut.concat("<li><a title=\"Mixx\" href=\"javascript:window.location='http://www.mixx.com/submit?page_url=" + Url.encode(vLink) + "&amp;title=" + Url.encode(vTitle) + "';\" target=\"_blank\" id=\"mixx\" rel=\"nofollow\"><img class=\"sociable-hovers\" alt=\"Mixx\" title=\"Mixx\" src=\"/template/Justin/images/mixx.png\"/></a></li>");
        strOut = strOut.concat("<li><a title=\"Google Bookmarks\" href=\"javascript:window.location='http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=" + Url.encode(vLink) + "&amp;title=" + Url.encode(vTitle) + "&amp;annotation=" + vAbstract + "';\" target=\"_blank\" id=\"google\" rel=\"nofollow\"><img class=\"sociable-hovers\" alt=\"Google Bookmarks\" title=\"Google Bookmarks\" src=\"/template/Justin/images/googlebookmark.png\"/></a></li>");
        strOut = strOut.concat("<li><a title=\"Reddit\" href=\"javascript:window.location='http://reddit.com/submit?url=" + Url.encode(vLink) + "&amp;title=" + Url.encode(vTitle) + "';\" target=\"_blank\" id=\"reddit\" rel=\"nofollow\"><img class=\"sociable-hovers\" alt=\"Reddit\" title=\"Reddit\" src=\"/template/Justin/images/reddit.png\"/></a></li>");
        strOut = strOut.concat("<li><a title=\"StumbleUpon\" href=\"javascript:window.location='http://www.stumbleupon.com/submit?url=" + Url.encode(vLink) + "&amp;title=" + Url.encode(vTitle) + "';\" target=\"_blank\" id=\"stumbleupon\" rel=\"nofollow\"><img class=\"sociable-hovers\" alt=\"StumbleUpon\" title=\"StumbleUpon\" src=\"/template/Justin/images/stumbleupon.png\"/></a></li>");
        strOut = strOut.concat("<li><a title=\"Twitter\" href=\"javascript:window.location='http://twitter.com/home?status=" + Url.encode(vTitle) + " - " + Url.encode(vLink) + "';\" target=\"_blank\" id=\"twitter\" rel=\"nofollow\"><img class=\"sociable-hovers\" alt=\"Twitter\" title=\"Twitter\" src=\"/template/Justin/images/twitter.png\"/></a></li>");
        strOut = strOut.concat("<li><a title=\"Yahoo! Buzz\" href=\"javascript:window.location='http://buzz.yahoo.com/submit/?submitUrl=" + Url.encode(vLink) + "&amp;submitHeadline=" + Url.encode(vTitle) + "&amp;submitSummary=" + vAbstract + "&amp;submitCategory=science&amp;submitAssetType=text';\" target=\"_blank\" id=\"yahoobuzz\" rel=\"nofollow\"><img class=\"sociable-hovers\" alt=\"Yahoo! Buzz\" title=\"Yahoo! Buzz\" src=\"/template/Justin/images/yahoobuzz.png\"/></a></li>");
        strOut = strOut.concat("<li><a title=\"FriendFeed\" href=\"javascript:window.location='http://www.friendfeed.com/share?title=" + Url.encode(vTitle) + "&amp;link=" + Url.encode(vLink) + "';\" target=\"_blank\" id=\"friendfeed\" rel=\"nofollow\"><img class=\"sociable-hovers\" alt=\"FriendFeed\" title=\"FriendFeed\" src=\"/template/Justin/images/friendfeed.png\"/></a></li>");
        strOut = strOut.concat("<li><a title=\"Ping.fm\" href=\"javascript:window.location='http://ping.fm/ref/?link=" + Url.encode(vLink) + "&amp;title=" + Url.encode(vTitle) + "&amp;body=" + vAbstract + "';\" target=\"_blank\" id=\"ping.fm\" rel=\"nofollow\"><img class=\"sociable-hovers\" alt=\"Ping.fm\" title=\"Ping.fm\" src=\"/template/Justin/images/ping.png\"/></a></li>");
        strOut = strOut.concat("<li><a title=\"Technorati\" href=\"javascript:window.location='http://technorati.com/faves?add=" + Url.encode(vLink) + "';\" target=\"_blank\" id=\"technorati\" rel=\"nofollow\"><img class=\"sociable-hovers\" alt=\"Technorati\" title=\"Technorati\" src=\"/template/Justin/images/technorati.png\"/></a></li>");
        strOut = strOut.concat("<li><a title=\"Yahoo! Bookmarks\" href=\"javascript:window.location='http://bookmarks.yahoo.com/toolbar/savebm?u=" + Url.encode(vLink) + "&amp;t=" + Url.encode(vTitle) + "&opener=bm&amp;ei=UTF-8&amp;d=';\" target=\"_blank\" id=\"yahoo! bookmarks\" rel=\"nofollow\"><img class=\"sociable-hovers\" alt=\"Yahoo! Bookmarks\" title=\"Yahoo! Bookmarks\" src=\"/template/Justin/images/yahoomyweb.png\"/></a></li>");
        strOut = strOut.concat('<li><a title=\'E-mail this story to a friend!\' href=\'javascript:openWin("/Email?vLink=' + Url.encode(vLink) + '","450","300");\' id=\'email\' rel=\'nofollow\'><img class=\'sociable-hovers\' alt=\'E-mail this story to a friend!\' title=\'E-mail this story to a friend!\' src=\'/template/Justin/images/email_link.png\'/></a></li>');
        strOut = strOut.concat("<li><a title=\"Netvibes\" href=\"javascript:window.location='http://www.netvibes.com/share?title=" + Url.encode(vTitle) + "&amp;url=" + Url.encode(vLink) + "';\" target=\"_blank\" id=\"netvibes\" rel=\"nofollow\"><img class=\"sociable-hovers\" alt=\"Netvibes\" title=\"Netvibes\" src=\"/template/Justin/images/netvibes.png\"/></a></li>");
        strOut = strOut.concat("<li class=\"sociablelast\"><a title=\"RSS\" href=\"javascript:window.location='http://blog.meotom.net/Resource/RSS/Trang-Chu.xml';\" target=\"_blank\" id=\"rss\" rel=\"nofollow\"><img class=\"sociable-hovers\" alt=\"RSS\" title=\"RSS\" src=\"/template/Justin/images/rss.png\"/></a></li>");
        strOut = strOut.concat("</ul>");
        strOut = strOut.concat("</div>");

        gmobj(vId).innerHTML = strOut;
    },
    doCol: function() {
        if (b) {
            gmobj("commentct").style.display = "none";
            b = false;
        }
        else {
            gmobj("commentct").style.display = "";
            b = true;
        }
    },
    GoTo: function(strLink) {
        location.href = strLink;
    },
    InsertEmoticon: function(vEmo, vTextArea) {
        gmobj(vTextArea).value += vEmo;
    },
    getWeather: function(vFile) {
        Util.writeWeather(vFile);
    },
    getComment: function(vId, vType) {
        try {
            var vFile = "";
            if (vType == 0) {
                vFile = HexToDec(gmobj("txtId").value.replace(".aspx", "").replace(".htm", ""));
            } else if (vType == 1) {
                vFile = gmobj("txtId").value;
            }
            AjaxRequest.get(
	        {
	            "url": "/Resource/Comments/Comments_" + vFile + ".htm"
	            , 'onLoading': function(req) { $("#divLoading").show(); }
		        , 'onSuccess': function(req) { gmobj(vId).innerHTML = req.responseText; $("#divLoading").hide(); }
		        , 'onError': function(req) { $("#divLoading").hide(); }
	        });
        } catch (err) {
            $("#divLoading").hide();
            return "";
        }
    },
    submitComment: function(theform) {
        gmobj("btnSubmit").disabled = true;
        var tomatch = /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/;
        if (gmobj("txtFullName").value.length > 50) {
            alert("Full Name is too long !!");
            gmobj("txtFullName").focus();
            gmobj("btnSubmit").disabled = false;
            return false;
        } else if (gmobj("txtEmail").value == "") {
            alert("Email require !!");
            gmobj("txtEmail").focus();
            gmobj("btnSubmit").disabled = false;
            return false;
        } else if (!echeck(gmobj("txtEmail").value)) {
            alert("Email incorrect format !!!");
            gmobj("txtEmail").focus();
            gmobj("btnSubmit").disabled = false;
            return false;
        } else if (gmobj("txtCode").value.length != 4) {
            alert("Secure Code require !!!");
            gmobj("txtCode").focus();
            gmobj("btnSubmit").disabled = false;
            return false;
        } else if (gmobj("txtBody").value.length < 5) {
            alert("Content is too short !!");
            gmobj("txtBody").focus();
            gmobj("btnSubmit").disabled = false;
            return false;
        } else if (gmobj("txtBody").value.length > 4000) {
            alert("Content is too long !!");
            gmobj("txtBody").focus();
            gmobj("btnSubmit").disabled = false;
            return false;
        } else {
            var strComment = "";
            var TotalComment = 0;
            if (gmobj("Comments") != null) {
                TotalComment = gmobj("Comments").innerHTML.replace("Comments (", "").replace(")", "");
            }

            var status = AjaxRequest.submit(
            theform
            , {
                'onLoading': function() { gmobj("btnSubmit").disabled = true; $("#divLoading").show(); }
            , 'onSuccess': function(req) {
                var CommentResponse = req.responseText;
                var CommentItem = CommentResponse.split(",");

                if (CommentResponse == "* Sai mã xác nhận.") {
                    alert("* Invalid secure code .");
                    ChangeImage();
                    gmobj("txtCode").value = "";
                    $("#divLoading").hide();
                } else if (CommentItem.length == 5) {
                    if (CommentItem[0] == "Cam on ban da Comment!_") {
                        alert("Thanks for Comment!");
                        gmobj("txtBody").value = "";
                        ChangeImage();
                        gmobj("txtCode").value = "";
                        $("#divLoading").hide();

                        TotalComment = parseInt(TotalComment) + 1;
                        strComment = strComment.concat("<li id=\"Comments_").concat(TotalComment).concat("\">")
                        strComment = strComment.concat("<cite>").concat(CommentItem[1]).concat(":</cite><br />")
                        strComment = strComment.concat("<small class=\"commentmetadata\"><a href=\"#Comments_").concat(TotalComment).concat("\">").concat(CommentItem[4]).concat(" at ").concat(CommentItem[2]).concat("</a></small>")
                        strComment = strComment.concat("<p>").concat(CommentItem[3]).concat("</p>")
                        strComment = strComment.concat("<span class=\"number\">").concat(TotalComment).concat("</span>")
                        strComment = strComment.concat("</li>")
                        if (gmobj("Comments") != null) {
                            gmobj("Comments").innerHTML = "Comments (" + TotalComment + ")";
                            gmobj("CommentList").innerHTML += strComment;
                        } else {
                            location.reload();
                        }
                    }
                } else {
                    alert(req.responseText);
                    gmobj("txtCode").value = "";
                    $("#divLoading").hide();
                }
            }
            }
            );
            gmobj("btnSubmit").value = "Submit Comment";
            gmobj("btnSubmit").disabled = false;
            return false;
        }
        return false;
    },
    checkArticlePass: function() {
        AjaxRequest.get(
    	    {
    	        "url": "/Services/ValidateArticle.ashx?sPath=".concat(gmobj("txtUrl").value).concat("&ArticleID=").concat(gmobj("txtArticleID").value).concat("&UserPass=").concat(gmobj("txtPassword").value)
    	        , 'onLoading': function() { gmobj("txtResponse").innerHTML = "Loading..."; }
    		    , 'onSuccess': function(req) {
    		        if (req.responseText == "OK") {
    		            Util.GoTo("/" + gmobj("txtUrl").value + "-" + gmobj("txtArticleID").value);
    		        } else if (req.responseText == "Fail") {
    		            gmobj("txtResponse").innerHTML = "* Sai mat khau !!!";
    		        }
    		    }
    		    , 'onError': function(req) {
    		        gmobj("txtResponse").innerHTML = req.statusText;
    		    }
    	    });
    },
    writeEmoticons: function(vId) {
        AjaxRequest.get(
    	    {
    	        "url": "/Resource/Emoticons.htm"
    	        , 'onLoading': function() { gmobj(vId).innerHTML = "Loading..."; }
    		    , 'onSuccess': function(req) {
    		        gmobj(vId).innerHTML = req.responseText;
    		    }
    		    , 'onError': function(req) {
    		        gmobj(vId).innerHTML = req.statusText;
    		    }
    	    });
    },
    writeCatName: function(ArticleID) {
        AjaxRequest.get(
    	    {
    	        "url": "/Services/Dashboard.ashx?action=GetCatName&ArticleID=" + ArticleID
    	        , 'onLoading': function(req) { $("#divLoading").show(); }
    		    , 'onSuccess': function(req) {
    		        gmobj("ArticleCat___" + ArticleID).innerHTML = req.responseText;
    		        Util.writeTagName(ArticleID);
    		        $("#divLoading").hide();
    		    }
    		    , 'onError': function(req) {

    		    }
    	    });
    },
    writeTagName: function(ArticleID) {
        AjaxRequest.get(
            {
                "url": "/Services/Dashboard.ashx?action=GetTagName&ArticleID=" + ArticleID
    	        , 'onLoading': function(req) { $("#divLoading").show(); }
    		    , 'onSuccess': function(req) {
    		        if (req.responseText != "") {
    		            gmobj("ArticleCat___" + ArticleID).innerHTML += "<br />Tags: " + req.responseText;
    		        }
    		        $("#divLoading").hide();
    		    }
    		    , 'onError': function(req) {

    		    }
            });
    },
    writeWeather: function(vFile) {
        AjaxRequest.get(
    	{
    	    "url": "/Resource/Weather/" + vFile + ".xml"
    	    , 'onLoading': function(req) { $("#divLoading").show(); }
    		, 'onSuccess': function(req) {
    		    var Item = req.responseXML.getElementsByTagName('Item');
    		    var AdImg = "", AdImg1 = "", AdImg2 = "", Weather = "", strWrite = "";

    		    AdImg = getNodeValue(req.responseXML.getElementsByTagName('Item').item(0).getElementsByTagName('AdImg'));
    		    AdImg1 = getNodeValue(req.responseXML.getElementsByTagName('Item').item(0).getElementsByTagName('AdImg1'));
    		    AdImg2 = getNodeValue(req.responseXML.getElementsByTagName('Item').item(0).getElementsByTagName('AdImg2'));
    		    Weather = getNodeValue(req.responseXML.getElementsByTagName('Item').item(0).getElementsByTagName('Weather'));

    		    //alert(Weather);
    		    strWrite += "<img src='/images/Weather/" + AdImg + "' border='0' width='36' height='35' />&nbsp;";
    		    strWrite += "<img src='/images/Weather/" + AdImg1 + "' border='0' width='19' height='28' />";
    		    strWrite += "<img src='/images/Weather/" + AdImg2 + "' border='0' width='19' height='28' />";
    		    strWrite += "<img src='/images/Weather/c.gif' width='35' height='28' /><br />";
    		    strWrite += Weather;
    		    gmobj("myWeather").innerHTML = strWrite;
    		    $("#divLoading").hide();
    		}
    		, 'onError': function(req) {
    		    $("#divLoading").hide();
    		}
    	});
    },
    ChangeLogo: function(vType) {
        if (vType == 0) {
            $("#logo").css("background-position", "0px -55px");
            $(".header-text h1 a").css("color", "#AC0000");
        } else {
            $("#logo").css("background-position", "0px 0px");
            $(".header-text h1 a").css("color", "#000000");
        }
    },
    InsertReplyUser: function(vCommentIndex) {
        if (gmobj("txtBody").value.length == 0) {
            gmobj("txtBody").value += "@" + gmobj("Comments_User_" + vCommentIndex).innerHTML.replace(/<a .*?>/g, "").replace(/<\/a>/g, "") + " ";
        } else {
            gmobj("txtBody").value += " @" + gmobj("Comments_User_" + vCommentIndex).innerHTML.replace(/<a .*?>/g, "").replace(/<\/a>/g, "") + " ";
        }
    }
}

function gmobj(mtxt) { if (document.getElementById) { m = document.getElementById(mtxt) } else if (document.all) { m = document.all[mtxt] } else if (document.layers) { m = document[mtxt] } return m; }

function echeck(str) {

    var at = "@"
    var dot = "."
    var lat = str.indexOf(at)
    var lstr = str.length
    var ldot = str.indexOf(dot)
    if (str.indexOf(at) == -1) {
        //alert("Email sai định dạng.")
        return false
    }

    if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
        //alert("Email sai định dạng.")
        return false
    }

    if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
        //alert("Email sai định dạng")
        return false
    }

    if (str.indexOf(at, (lat + 1)) != -1) {
        //alert("Email sai định dạng.")
        return false
    }

    if (str.substring(lat - 1, lat) == dot || str.substring(lat + 1, lat + 2) == dot) {
        //alert("Email sai định dạng.")
        return false
    }

    if (str.indexOf(dot, (lat + 2)) == -1) {
        //alert("Email sai định dạng.")
        return false
    }

    if (str.indexOf(" ") != -1) {
        //alert("Email sai định dạng.")
        return false
    }
    return true
}

function vote_poll(the_form) {
    width = 550;
    height = 250;
    top_val = (screen.height - height) / 2 - 30;
    if (top_val < 0) { top_val = 0; }
    left_val = (screen.width - width) / 2;

    window.open('', the_form.name, "toolbar=0,location=0,status=0,menubar=0,scrollbars=0,resizable=0,width=" + width + ",height=" + height + ", top=" + top_val + ",left=" + left_val);
    the_form.submit();
}

function openImage(vLink, vHeight, vWidth) {
    var sLink = (typeof (vLink.href) == 'undefined') ? vLink : vLink.href;

    if (sLink == '') {
        return false;
    }

    winDef = 'status=no,resizable=yes,scrollbars=yes,toolbar=no,location=no,fullscreen=yes,titlebar=yes,height='.concat(vHeight).concat(',').concat('width=').concat(vWidth).concat(',');
    winDef = winDef.concat('top=').concat((screen.height - vHeight) / 2).concat(',');
    winDef = winDef.concat('left=').concat((screen.width - vWidth) / 2);
    newwin = open('', '_blank', winDef);
    newwin.document.writeln('<body topmargin="0" leftmargin="0" marginheight="0" marginwidth="0">');
    newwin.document.writeln('<a href="" onClick="window.close(); return false;"><img src="', sLink, '" border=0></a>');
    newwin.document.writeln('</body>');

    if (typeof (vLink.href) != 'undefined') {
        return false;
    }
}
function openWin(linkID, w, h) {
    width = w;
    height = h;
    top_val = (screen.height - height) / 2 - 30;
    if (top_val < 0) { top_val = 0; }
    left_val = (screen.width - width) / 2;

    //linkID+="?id="+id;
    window.open(linkID, null, "toolbar=0,location=0,status=1,menubar=0,scrollbars=0,resizable=0,width=" + width + ",height=" + height + ", top=" + top_val + ",left=" + left_val);
    //the_form.submit();
}

function ShowSearch() {
    if (gmobj("txtSearch").value.length < 3) {
        alert("Tu khoa khong duoc nho hon 3 ky tu !!");
        gmobj("txtSearch").focus();
    } else {
        location.href = "/Search.aspx?s=" + Url.encode(gmobj("txtSearch").value) + "&Page=1";
    }
}
/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/

var Url = {

    // public method for url encoding
    encode: function(string) {
        return escape(this._utf8_encode(string));
    },

    // public method for url decoding
    decode: function(string) {
        return this._utf8_decode(unescape(string));
    },

    // private method for UTF-8 encoding
    _utf8_encode: function(string) {
        string = string.replace(/\r\n/g, "\n");
        var utftext = "";

        for (var n = 0; n < string.length; n++) {

            var c = string.charCodeAt(n);

            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if ((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }

        }

        return utftext;
    },

    // private method for UTF-8 decoding
    _utf8_decode: function(utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;

        while (i < utftext.length) {

            c = utftext.charCodeAt(i);

            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if ((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i + 1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i + 1);
                c3 = utftext.charCodeAt(i + 2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }

        }

        return string;
    }

}

function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function HexToDec(input) {
    var rt = 0;
    var cha = '';
    var temp;
    var len = input.length;
    for (var i = 1; i <= len; i++) {
        cha = Left(input, 1);
        switch (cha) {
            case 'A': case 'a': temp = 10; break;
            case 'B': case 'b': temp = 11; break;
            case 'C': case 'c': temp = 12; break;
            case 'D': case 'd': temp = 13; break;
            case 'E': case 'e': temp = 14; break;
            case 'F': case 'f': temp = 15; break;
            default: temp = parseInt(cha); break;
        }
        rt = rt + temp * Math.pow(16, len - i);
        input = Right(input, len - i);
    }
    return rt;
}
function LTrim(iStr) {
    while (iStr.charCodeAt(0) <= 32) {
        iStr = iStr.substr(1);
    }
    return iStr;
}

function RTrim(iStr) {
    while (iStr.charCodeAt(iStr.length - 1) <= 32) {
        iStr = iStr.substr(0, iStr.length - 1);
    }
    return iStr;
}

function Trim(iStr) {
    while (iStr.charCodeAt(0) <= 32) {
        iStr = iStr.substr(1);
    }

    while (iStr.charCodeAt(iStr.length - 1) <= 32) {
        iStr = iStr.substr(0, iStr.length - 1);
    }

    return iStr;
}

function Left(str, n) {
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else
        return String(str).substring(0, n);
}


function Right(str, n) {
    if (n <= 0)
        return "";
    else if (n > String(str).length)
        return str;
    else {
        var iLen = String(str).length;
        return String(str).substring(iLen, iLen - n);
    }
}